<template>
	<view>
		<view class="bg_fff P_2 B_radius_5 M_3">
			
			<view style="display: flex;align-items: flex-end;justify-content: center;">
				<view class="fontS_30 font_weight_bold PTB_2">
					{{Number(num).toFixed(2)}}
				</view>
				<view v-if="id==2" class="PB_3 PL_2">
					≈{{(num*rate).toFixed(2)}}CNY
				</view>
				<view v-else class="PB_3 PL_2">
					≈{{Number(num).toFixed(2)}}CNY
				</view>
			</view>
			
			
			<view class="flex_rowC font_weight_bold PB_2">
				总账户资产( {{id==1?'KSA':'USDT'}})
			</view>
			
			
			
			<view class="flex_rowC PTB_2 ">
				<view @click="uOpenWin('./cashIn')" class="pub_btn B_radius_5 PTB_1 PLR_3">
					充币
				</view>
				<view @click="uOpenWin('./cashOut')" class="pub_btn B_radius_5 PTB_1 PLR_3 MLR_4">
					提币
				</view>
				<view @click="uOpenWin('./transEach')" class="pub_btn B_radius_5 PTB_1 PLR_3">
					闪兑
				</view>
			</view>
		</view>
		
		<view class="bg_fff PLR_3 PB_4">
			<view class="flex_row_between PTB_4"  @click="uOpenWin('./usdtLog')">
				<view class="flex_rowL">
					<image class="W_4vw MR_2" src="../../static/USDT.png" mode="widthFix"></image>
					<view class="pub_color font_weight_bold">
						USDT
					</view>
				</view>
				<image class="W_4vw" src="../../static/goyou.png" mode="widthFix"></image>
				
			</view>
			
			<view class="flex_row_between line_bom">
				<view class="flex_colC">
					<view class="font_weight_bold fontS_14">
						{{Number(usdt.money).toFixed(2)}}
					</view>
					<view class="PB_2 color_gray ">
						可用余额
					</view>
				</view>
				<view class="flex_colC">
					<view class="font_weight_bold">
						{{Number(usdt.frozen).toFixed(2)}}
					</view>
					<view class="PB_2 color_gray fontS_12 PT_1">
						冻结
					</view>
					
				</view>
				<view class="flex_colC">
					
					<view class="font_weight_bold">
						{{Number(usdt.money*rate).toFixed(2)}}
					</view>
					<view class="PB_2 color_gray fontS_12">
						≈CNY
					</view>
					
				</view>
			</view>
			
			<view class="flex_row_between PTB_4" @click="uOpenWin('./ksaLog')">
				<view class="flex_rowL">
					<image class="W_4vw MR_2" src="../../static/KSA.png" mode="widthFix"></image>
					<view class="pub_color font_weight_bold">
						KSA
					</view>
				</view>
				<image class="W_4vw" src="../../static/goyou.png" mode="widthFix"></image>
				
			</view>
			
			<view class="flex_row_between">
				<view class="flex_colC">
					<view class="PB_2 color_gray fontS_12">
						可用余额
					</view>
					<view class="font_weight_bold">
						{{ksa.money}}
					</view>
				</view>
				<view class="flex_colC">
					<view class="PB_2 color_gray fontS_12">
						冻结
					</view>
					<view class="font_weight_bold">
						{{ksa.frozen}}
					</view>
				</view>
				<view class="flex_colC">
					<view class="PB_2 color_gray fontS_12">
						≈CNY
					</view>
					<view class="font_weight_bold">
						{{ksa.money}}
					</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				usdt:{},
				ksa:{},
				num:'',
				usdts:{},
				ksas:{},
				rate:1,
				id:'',
				timer:''
			}
		},
		onLoad(options) {
			this.id = options.id;
			this.getPray();
			this.getRate();
			this.getSort()
		},
		onPullDownRefresh() {
			//this.getSorts();
			this.getPray();
			this.getRate();
			console.log('refresh');
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onHide() {
			let _this = this;
			clearInterval(_this.timer)
		},
		methods: {
			getRate(){
				let _this = this;
				this.$req('index/getRate',{},function(res){
					_this.rate = res.data.rate
					//console.log(res)
				})
			},
			getPray(){
				let _this = this;
				this.$req('account/getTransactions',{},function(res){
					console.log(res)
					// _this.getTotal();
					clearInterval(_this.timer)
					_this.timer = setInterval(()=>{
						_this.getSort();
					},10000)
					_this.getSort();
				})
			},
			// getTotal(){
			// 	let _this = this;
			// 	this.$req('account/sumMoney',{},function(res){
			// 		_this.num = res.data.sumMoney;
			// 	})
			// },
			getSort(){
				let _this = this;
				this.$req('account/index',{},function(res){
					let list = res.data;
					list.forEach((item)=>{
						if(item.currency_name=='KSA'){
							_this.ksa = item;
							_this.ksas = item.currency
						}
						if(item.currency_name=='USDT'){
							_this.usdt = item;
							// _this.usdt = item.currency
						}
						if(_this.id == 1){
							_this.num = _this.ksa.money
						}else{
							_this.num = _this.usdt.money
						}
					})
				})
			}
		}
	}
</script>

<style>

</style>
